//
//  MainViewController.swift
//  01-SinaWeibo
//
//  Created by pc on 15/11/8.
//  Copyright © 2015年 file. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    //为了第一眼就能看到事件的响应方法 放到这个上面
    @objc private func composeDidClick() {
        
        print(__FUNCTION__)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        

        //由于 tabBar是只读 不能够直接操作  如果要修改  可以使用KVC
        let mainTabBar = MainTabBar()
        //KVC赋值
        setValue(mainTabBar, forKey: "tabBar")
        
        // 添加子视图控制器
        addChildViewControllers()
        
        //验证 tabBar 
        //print(tabBar.classForCoder)
        
        
        //3.设置加号按钮的点击事件
        mainTabBar.compostBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
        
    }
    
    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscovrTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    
    }
    
    
    

    //弄了一个子视图
    private func addChildViewController(vc: UIViewController, title: String, imageName: String){
    
        //self.tabBar.tintColor = UIColor.orangeColor()
        //实例化导航控制器
        let nav = UINavigationController(rootViewController: vc)
    
//        title = "首页"
//        nav.title = "首页"
//        hom.title = "首页"
//        hom.tabBarItem.image = UIImage(named: "tabbar_hom")
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置底部控件点击之后的状态
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName :  UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
        
        //添加
        
        addChildViewController(nav)
    
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
